﻿using Avalonia.Controls;
using Avalonia.Interactivity;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using DynamicData;
using System.Linq;

namespace testapp.ViewModels
{
    public class MainWindowViewModel : ViewModelBase
    {
   

        public ObservableCollection<VillageInfo> VillageInfo { get; set; }

        public ObservableCollection<Node> Nodes { get; }

        public ObservableCollection<Node> SelectedNodes { get; }
        public MainWindowViewModel()
        {
            SelectedNodes= new ObservableCollection<Node>();
              var villages = new List<VillageInfo>
            {
                new VillageInfo { Code = "康定市", PostalCode = "513301000000", FullName = "康定市", TibetanName = "བཀང་འདིན་" },
                new VillageInfo { Code = "姜维乡", PostalCode = "513301205000", FullName = "姜维乡", TibetanName = "ཅང་ཝེ་" },
                new VillageInfo { Code = "日安村", PostalCode = "513301205202", FullName = "日安村", TibetanName = "རི་ཨན་" },
                // 添加更多数据...
            };

            VillageInfo = new ObservableCollection<VillageInfo>(villages);

            Nodes = new ObservableCollection<Node>
                        {
                                new Node("菜单1", new ObservableCollection<Node>
                                {
                                       new Node("子菜单1-1"), new Node("子菜单1-2"), new Node("子菜单1-3")
                                }),
                                  new Node("菜单2", new ObservableCollection<Node>
                                {
                                        new Node("子菜单2-1"), new Node("子菜单2-2"), new Node("子菜单2-3")
                                })

                        };

            var moth = Nodes.First();
            if (moth != null) SelectedNodes.Add(moth);
        }

#pragma warning disable CA1822 // Mark members as static
        public string username => "admin";

        public string password => "password";
#pragma warning restore CA1822 // Mark members as static

        private bool _isMenuExpanded = true;
        private GridLength _menuWidth = new GridLength(200);



        public GridLength MenuWidth
        {
            get => _menuWidth;
            set
            {
                if (_menuWidth != value)
                {
                    _menuWidth = value;
                    OnPropertyChanged();
                }
            }
        }



        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }


        public event PropertyChangedEventHandler PropertyChanged;

     

    }
   

    public class VillageInfo
    {
        public string Code { get; set; }
        public string PostalCode { get; set; }
        public string FullName { get; set; }
        public string TibetanName { get; set; }
    }


    public class Node
    {
        public ObservableCollection<Node>? SubNodes { get; }
        public string Title { get; }

        public Node(string title)
        {
            Title = title;
        }

        public Node(string title, ObservableCollection<Node> subNodes)
        {
            Title = title;
            SubNodes = subNodes;
        }
    }

}


